﻿using System.Collections.ObjectModel;

namespace MDCAdminTool
{
    public static class CacheReports
    {
        public static Collection<NameValue> CacheNameSizesByHost( this CacheHost host )
        {
            var coll = new Collection<NameValue>();

            foreach( var item in host.CacheNames )
            {
                long val = 0 ;

                if ( item.NamedCacheStats == null )
                     item.LoadStatistics();

                if ( item.NamedCacheStats != null )
                {
                    val = item.NamedCacheStats.Size;
                }

                coll.Add( 
                    new NameValue 
                    { 
                        Name  = item.Name , 
                        Value = val
                    } );           
            }

            return coll;
        }
        public static Collection<NameValue> HostSize( this CacheHost host )
        {
            host.LoadStatistics();
            return 
                new Collection<NameValue>
                    {
                        new NameValue 
                        { 
                            Name = host.Name , 
                            Value = host.HostCacheStats.Size
                        }
                    };
        }
        public static Collection<NameValue> ClusterSize( this CacheCluster cluster )
        {
            var coll = new Collection<NameValue>();

            foreach ( var item in cluster.Hosts )
            {
                coll.Add(
                    new NameValue
                    {
                        Name  = item.Name ,
                        Value = item.HostCacheStats.Size
                    } );
            }

            return coll;
        }

        public static Collection<NameValue> HostStat( this CacheHost host )
        {
            return
                new Collection<NameValue>
                   {
                       new NameValue{ Name = "Items"       , Value = host.HostCacheStats.ItemCount },
                       new NameValue{ Name = "Miss"        , Value = host.HostCacheStats.MissCount },
                       new NameValue{ Name = "Named Cache" , Value = host.HostCacheStats.NamedCacheCount },
                       new NameValue{ Name = "Regions"     , Value = host.HostCacheStats.RegionCount },
                       new NameValue{ Name = "Requests"    , Value = host.HostCacheStats.RequestCount }
                   };
        }
        public static Collection<NameValue> CacheNameStat( this MdcCache cache )
        {
            return
                new Collection<NameValue>
                   {
                       new NameValue{ Name = "Items"       , Value = cache.NamedCacheStats.ItemCount },
                       new NameValue{ Name = "Miss"        , Value = cache.NamedCacheStats.MissCount },
                       new NameValue{ Name = "Regions"     , Value = cache.NamedCacheStats.RegionCount },
                       new NameValue{ Name = "Requests"    , Value = cache.NamedCacheStats.RequestCount }
                   };
        }
    }
}
